package com.lz.ccjdemo.utils;

import android.content.Context;

import com.lz.ccjdemo.utils.dialog.LoadingDialog;

/**
 * 全局loading
 */
public class LoadingUtils {

    static LoadingDialog loadingDialog;

    public static void showLoading(Context context) {
        showLoading(context, "加载中...");
    }

    public static void showLoading(Context context, String msg) {
        if (loadingDialog == null) {
            LoadingDialog.Builder builder = new LoadingDialog.Builder(context)
                    .setMessage(msg)
                    .setCancelable(false)
                    .setCancelOutside(false);
            loadingDialog = builder.create();
        } else {
            loadingDialog.dismiss();
            LoadingDialog.Builder builder = new LoadingDialog.Builder(context)
                    .setMessage(msg)
                    .setCancelable(false)
                    .setCancelOutside(false);
            loadingDialog = builder.create();
        }
        loadingDialog.show();
    }

    public static void hideLoading() {
        if (loadingDialog != null && loadingDialog.isShowing()) {
            loadingDialog.dismiss();
        }
    }
}
